#include <iostream.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
main()
{
	cout<<"================================="<<endl;
	cout<<"NAMA KELOMPOK"<<endl;
	cout<<"CHRISNA BATE OSADANA [1310511076]"<<endl;
	cout<<"FAHMI RAMADHAN       [1310511077]"<<endl;	
	cout<<"BIMA SAKTI WICAKSONO [1310511077]"<<endl;
	cout<<"AMARULLAH ILHAQ      [1310511089]"<<endl;
	cout<<"================================="<<endl<<endl;
	cout<<"FIRTS COME FIRTS SERVED"<<endl<<endl;
	int i=0,m=0;
	int jm;
	cout<<"jumlah proses yang diinginkan : ";cin>>jm ;
	int x=0;
	int a[jm],b[jm],n[jm],p[jm];
	cout<<endl<<"masukan arrival time P1 : 0"<<endl;
	a[0]=0;p[0]=1;
	 for(int i=1;i<jm;i++){
		 cout<<endl<<"masukan arrival time P"<<i+1<<" : ";cin>>a[i];
		 p[i]=i+1;}
	 for(i=0;i<jm;i++){
		 cout<<endl<<"masukan burst time P"<<i+1<<" : ";cin>>b[i];
	 }
	 int temp,j;
	 
	for(i=0;i<jm;i++){
		
	for(j=0;j<jm;j++){
	if(a[i]<a[j]){
		temp=a[j];
		a[j]=a[i];
		a[i]=temp;
		
		temp=p[j];
		p[j]=p[i];
		p[i]=temp;

		temp=b[j];
		b[j]=b[i];
		b[i]=temp;

		}
	}}
	
	
	for (i=0;i<jm;i++){
		cout<<" ___  ___";
	}cout<<endl;cout<<"|";
	for(i=0;i<jm;i++){
		
		cout<<"___P"<<p[i]<<"___|";
	}
	cout<<endl<<m;
	for(i=0;i<jm;i++){
	
	m=m+b[i];
	n[i]=m;
	cout<<"        "<<n[i];}
	for(i=0;i<jm;i++){
		x=x+n[i];
	}
	int z;
	z=a[0];
	for(i=0;i<jm-1;i++){
	z=z+n[i]-a[i+1];}
	cout<<endl<<"======================================================================"<<endl;
	cout<<"Proses       burst time      arrival time    "<<endl;
	for(i=0;i<jm;i++){
	cout<<"   P"<<p[i]<<"    |        "<<b[i]<<"      |        "<<a[i]<<"        | "<<endl;}
	cout<<"======================================================================"<<endl;
	float ta; 
	ta = (float)x/jm;
	cout<<endl<<"TURN AROUND TIME : "<<ta;
	float wt;
	wt = (float) z/jm;
	cout<<endl<<"WAITING TIME : "<<wt<<endl;
	system("PAUSE");
}